<?php


namespace api\modules\v1\controllers;

use api\controllers\OnAuthController;
use common\models\base\PatientDiseases;
use common\models\marketing\Tags;
use services\base\PatientDiseasesService;
use services\base\ProjectService;
use services\dengta\robot\WechatService;
use services\marketing\TagsService;
use services\patient\ConsumptionService;
use services\patient\UserService;
use Yii;

class DengtaController extends OnAuthController
{
    public $modelClass = '';

    public $optional = ['project-list', 'project-info', 'patient-info', 'project-patient-mobile', 'project-patient-consumption', 'patient-list-by-reg', 'patient-arrive-list', 'patient-diseases-list', 'tags-list', 'visit-consumption', 'consumption-list', 'patient-by-wechat-no'];

    /**
     * @api {get} /v1/dengta/project-list           项目列表
     * @apiName project-list
     * @apiGroup Dengta
     *
     * @apiParam {String} column                    字段
     * @apiParam {String} status                    状态
     * @apiParam {String} indexBy                   索引
     *
     * @apiSuccess {String} code                    状态码
     * @apiSuccess {String} message                 提示信息
     * @apiSuccess {Object} data                    返回内容
     *
     */
    public function actionProjectList()
    {
        $param = Yii::$app->request->get();

        $service = new ProjectService();
        return $service->getList($param);
    }

    /**
     * @api {get} /v1/dengta/project-info           项目信息
     * @apiName project-info
     * @apiGroup Dengta
     *
     * @apiParam {String} name_sx                    字段
     *
     * @apiSuccess {String} code                    状态码
     * @apiSuccess {String} message                 提示信息
     * @apiSuccess {Object} data                    返回内容
     *
     */
    public function actionProjectInfo()
    {
        $param = Yii::$app->request->get();

        $service = new ProjectService();
        return $service->getInfoByNameSx($param);
    }

    /**
     * @api {get} /v1/dengta/patient-info           患者信息
     * @apiName patient-info
     * @apiGroup Dengta
     *
     * @apiParam {String} column                    字段
     * @apiParam {String} project_id                项目ID
     * @apiParam {String} patient_card_id           诊疗号ID
     *
     * @apiSuccess {String} code                    状态码
     * @apiSuccess {String} message                 提示信息
     * @apiSuccess {Object} data                    返回内容
     *
     */
    public function actionPatientInfo()
    {
        $param = Yii::$app->request->get();

        $service = new UserService();
        return $service->findInfoByDt($param);
    }

    /**
     * @api {get} /v1/dengta/project-patient-mobile           项目患者手机
     * @apiName project-patient-mobile
     * @apiGroup Dengta
     *
     * @apiParam {String} project_id                项目ID
     * @apiParam {String} mobile                    手机号
     *
     * @apiSuccess {String} code                    状态码
     * @apiSuccess {String} message                 提示信息
     * @apiSuccess {Object} data                    返回内容
     *
     */
    public function actionProjectPatientMobile()
    {
        $param = Yii::$app->request->get();
        $param['project_id'] = $param['project_id'] ?? 0;
//        $param['mobile'] = $param['mobile'] ?? '';

        $service = new UserService();
        return $service->getPatientMobiles($param);
    }

    /**
     * @api {get} /v1/dengta/project-patient-consumption           项目患者手机
     * @apiName project-patient-consumption
     * @apiGroup Dengta
     *
     * @apiParam {String} project_id                项目ID
     * @apiParam {String} patient_card_id           诊疗号ID
     * @apiParam {String} end_time                  结束时间
     *
     * @apiSuccess {String} code                    状态码
     * @apiSuccess {String} message                 提示信息
     * @apiSuccess {Object} data                    返回内容
     *
     */
    public function actionProjectPatientConsumption()
    {
        $param = Yii::$app->request->get();
        $param['project_id'] = $param['project_id'] ?? 0;
//        $param['mobile'] = $param['mobile'] ?? '';

        $service = new ConsumptionService();
        return $service->getDtList($param);
    }

    /**
     * @api {get} /v1/dengta/patient-list-by-reg           项目患者手机
     * @apiName patient-list-by-reg
     * @apiGroup Dengta
     *
     * @apiParam {String} column                    字段
     * @apiParam {String} project_id                项目ID
     * @apiParam {String} type                      类型【1手机、2微信、3患者姓名】
     * @apiParam {String} start_time                开始时间
     * @apiParam {String} end_time                  结束时间
     *
     * @apiSuccess {String} code                    状态码
     * @apiSuccess {String} message                 提示信息
     * @apiSuccess {Object} data                    返回内容
     *
     */
    public function actionPatientListByReg()
    {
        $param = Yii::$app->request->get();
        $param['project_id'] = $param['project_id'] ?? 0;
//        $param['mobile'] = $param['mobile'] ?? '';

        $service = new UserService();
        return $service->getPatientListByReg($param);
    }

    /**
     * @api {post} /v1/dengta/patient-arrive-list    白友已到患者
     * @apiName patient-arrive-list
     * @apiGroup Dengta
     *
     * @apiParam {String} patient_card_id_arr
     * @apiParam {String} relation_baiyou_pname
     * @apiParam {String} project_id
     * @apiParam {String} patient_card_id
     * @apiParam {String} matching
     * @apiParam {String} start_time                开始时间
     * @apiParam {String} end_time                  结束时间
     *
     * @apiSuccess {String} code                    状态码
     * @apiSuccess {String} message                 提示信息
     * @apiSuccess {Object} data                    返回内容
     *
     */
    public function actionPatientArriveList()
    {
        $param = Yii::$app->request->post();
        $param['project_id'] = $param['project_id'] ?? 0;
//        $param['mobile'] = $param['mobile'] ?? '';

        $service = new UserService();
        return $service->getPatientArriveList($param);
    }

    /**
     * @api {get} /v1/dengta/patient-diseases-list    病种列表
     * @apiName patient-diseases-list
     * @apiGroup Dengta
     *
     *
     * @apiSuccess {String} code                    状态码
     * @apiSuccess {String} message                 提示信息
     * @apiSuccess {Object} data                    返回内容
     *
     */
    public function actionPatientDiseasesList()
    {
        $param = Yii::$app->request->get();

        $service = new PatientDiseasesService();
        return $service->findList([
            'select' => ['id', 'diseases_name'],
            'status' => [PatientDiseases::STATUS_ENABLE, PatientDiseases::STATUS_INVALID]
        ]);
    }

    /**
     * @api {get} /v1/dengta/tags-list    标签列表
     * @apiName tags-list
     * @apiGroup Dengta
     *
     *
     * @apiSuccess {String} code                    状态码
     * @apiSuccess {String} message                 提示信息
     * @apiSuccess {Object} data                    返回内容
     *
     */
    public function actionTagsList()
    {
        $param = Yii::$app->request->get();

        $service = new TagsService();
        return $service->findList([
            'select' => ['id', 'tags_name'],
            'status' => [Tags::STATUS_ENABLE, Tags::STATUS_INVALID]
        ]);
    }

    /**
     * @api {post} /v1/dengta/visit-consumption           项目患者手机
     * @apiName visit-consumption
     * @apiGroup Dengta
     *
     * @apiParam {Array}  patient_card_id_arr       诊疗号IDs
     * @apiParam {Array}  project_id_arr            项目IDs
     * @apiParam {String} matching                  项目ID
     * @apiParam {String} type                      类型
     * @apiParam {String} start_time                开始时间
     * @apiParam {String} end_time                  结束时间
     *
     * @apiSuccess {String} code                    状态码
     * @apiSuccess {String} message                 提示信息
     * @apiSuccess {Object} data                    返回内容
     *
     */
    public function actionVisitConsumption()
    {
        $param = Yii::$app->request->post();
        $param['patient_card_id_arr'] = $param['patient_card_id_arr'] ?? [];
        $param['project_id_arr'] = $param['project_id_arr'] ?? [];
        $param['matching'] = $param['matching'] ?? 0;
        $param['type'] = $param['type'] ?? 0;

        $service = new ConsumptionService();
        return $service->getDtList1($param);
    }

    /**
     * @api {get} /v1/dengta/consumption-list       消费列表
     * @apiName consumption-list
     * @apiGroup Dengta
     *
     * @apiParam {String} patientCardId             诊疗号ID
     * @apiParam {String} projectId                 项目ID
     * @apiParam {String} regTime                   就诊时间
     *
     * @apiSuccess {String} code                    状态码
     * @apiSuccess {String} message                 提示信息
     * @apiSuccess {Object} data                    返回内容
     *
     */
    public function actionConsumptionList()
    {
        $param = Yii::$app->request->post();
        $param['project_id'] = $param['project_id'] ?? 0;
//        $param['mobile'] = $param['mobile'] ?? '';

        $service = new ConsumptionService();
        return $service->getDtList2($param);
    }

    /**
     * @api {get} /v1/dengta/patient-by-wechat-no       根据微信号获取患者信息
     * @apiName patient-by-wechat-no
     * @apiGroup Dengta
     *
     * @apiParam {String} patientCardId             诊疗号ID
     * @apiParam {String} projectId                 项目ID
     * @apiParam {String} regTime                   就诊时间
     *
     * @apiSuccess {String} code                    状态码
     * @apiSuccess {String} message                 提示信息
     * @apiSuccess {Object} data                    返回内容
     *
     */
    public function actionPatientByWechatNo()
    {
        $param = Yii::$app->request->post();
        $param['friend_wechatno'] = $param['friend_wechatno'] ?? '';

        $service = new WechatService();
        return $service->getPatientWechatInfoByContent($param['friend_wechatno']);
    }
}
